<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Tao
 * Date: 13-3-18
 * Time: 下午2:47
 * To change this template use File | Settings | File Templates.
 */
$con = mysql_connect('localhost','root','123456');

mysql_select_db('my_db');
mysql_query("SET NAMES UTF8");
$start = ($_REQUEST['start'] != '') ? $_REQUEST['start'] : 0;
$limit = ($_REQUEST['limit'] != '') ? $_REQUEST['limit'] : 10;

$count_sql = 'select * from persons';

$result = mysql_query($count_sql,$con);

if(!$result){
    die('{"success":false1,"message":"读取数据失败"}');
}
$count = 0;

if(mysql_num_rows($result) > 0){


    $count = mysql_num_rows($result);

    $sql = $count_sql . ' LIMIT ' . $start . ',' . $limit;

    $result = mysql_query($sql);

    if(!$result){
        die('{"success":false2,"message":读取数据失败","books":""}');
    }
    $arr = array();

    if(mysql_num_rows($result) > 0){
        while($obj = mysql_fetch_object($result)){
            $arr[] = $obj;
        }
        echo '{"success":true,"userCount":'.$count.',"books":'.json_encode($arr).'}';
    }else{
        die('{"success":false3,"message":"读取数据失败"}');
    }
}else{
    die('{"success":false4,"message":"读取数据失败"}');
}


//mysql_close($con);
?>